﻿



-- 增加监视点所属人员信息（所属区域门信息）
CREATE procedure [dbo].[JsdRyqx_Add]
@jsdbh varchar(18),
@sfzh varchar(18),
@sfhbmd bit,
@sfkqfq bit,
@yxjcsj datetime=null
as
declare 
@kh varchar(10),
@id int
--动态计算人员ID
select top 1 @id=ryid-1 from JsdRyqx_Info 
left join (select ryid idx from JsdRyqx_Info where jsdbh=@jsdbh) aa on(ryid=idx+1) where idx is null and ryid<>1
and jsdbh=@jsdbh
if(@id is null)
begin
	select @id=max(ryid) from JsdRyqx_Info where jsdbh=@jsdbh
end
else
begin
	set @id=@id-1
end

select @kh=kh from RyCa_Info where sfzh=@sfzh and cxsj is null
if not exists(select 1 from JsdRyqx_Info where jsdbh=@jsdbh and sfzh=@sfzh)
begin
	insert into JsdRyqx_Info values(@jsdbh,@sfzh,@kh,isnull(@id,0)+1,@sfhbmd,@sfkqfq,@yxjcsj)
end